package btree;

import btree.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution_230 {
    public int kthSmallest(TreeNode root, int k) {
        List<Integer> list = new ArrayList<>();
        dfs(root, list);
        return list.get(k - 1);
    }

    private void dfs(TreeNode root, List<Integer> list) {
        if (root.left != null)
            dfs(root.left, list);
        list.add(root.val);
        if (root.right != null)
            dfs(root.right, list);
    }
}
